<?php

namespace App\Admin\Controllers;

use App\Models\PresentCard;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class PresentCardController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '礼品卡管理';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new PresentCard);

        $grid->column('id', __('Id'));
        $grid->column('name', __('卡名称'));
        $grid->column('content', __('卡内容'));
        $grid->column('home_image', __('列表图'))->lightbox(['width' => 50, 'height' => 50]);
        $grid->column('head_image', __('详情图'))->lightbox(['width' => 50, 'height' => 50]);
        $grid->column('log_image', __('记录图'))->lightbox(['width' => 50, 'height' => 50]);
        $grid->column('font_color', __('字体颜色'));
        $grid->column('sort', __('排序'));
        $grid->column('created_at', __('创建时间'));

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(PresentCard::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('name', __('Name'));
        $show->field('content', __('Content'));
        $show->field('home_image', __('Home image'));
        $show->field('head_image', __('Head image'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new PresentCard);

        $form->text('name', __('卡名称'));
        $form->text('content', __('卡内容'));
        $form->image('home_image', '列表图')->move('images/presentcard/' . date("Ym/d", time()))->uniqueName();
        $form->image('head_image', '详情图')->move('images/presentcard/' . date("Ym/d", time()))->uniqueName();
        $form->image('log_image', '记录图')->move('images/presentcard/' . date("Ym/d", time()))->uniqueName();
        $form->text('font_color', '字体颜色')->default('');
        $form->number('sort', '排序')->default(0)->help('越小越靠左');

        return $form;
    }
}
